package com.core.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.core.base.dao.BaseHibernateDao;
import com.core.model.MenusCombineRoles;

/**
 * 角色菜单DAO
 * 
 * @author pt-chenqw
 *
 */
@Repository("menusCombineRolesDAO")
public class MenusCombineRolesDAO extends BaseHibernateDao<MenusCombineRoles> {
	
	/**
	 * 新增
	 * @param menusCombineRole
	 */
	public void addMenusCombineRoleByBatch(List<MenusCombineRoles> menusCombineRoles){
		for (MenusCombineRoles menusCombineRole : menusCombineRoles) {
			save(menusCombineRole);
		}
	}
	
	/**
	 * 根据角色ID查询
	 * @param roleID
	 * @return
	 */
	public List<MenusCombineRoles> getMenusCombineRolesByRoleID(Integer roleID){
		String hql = "from MenusCombineRoles where roleID = ?";
		return find(hql, roleID);
	}
	
	/**
	 * 根据菜单编码查询
	 * @param roleCode
	 * @return
	 */
	public MenusCombineRoles getMenusCombineRolesByMenuCode(String menuCode,String roleCode){
		String hql = "from MenusCombineRoles where menuCode = ? and roleCode = ?";
		return findOne(hql, menuCode,roleCode);
	}
	
	/**
	 * 根据菜单编码查询
	 * @param roleCode
	 * @return
	 */
	public MenusCombineRoles getMenusCombineRolesByMenuIDAndRoleID(Integer menuID,Integer roleID){
		String hql = "from MenusCombineRoles where menuID = ? and roleID = ?";
		return findOne(hql, menuID,roleID);
	}
	
	/**
	 * 删除授权菜单
	 * @param menusCombineRoles
	 */
	public void deleteMenusCombineRoles(List<MenusCombineRoles> menusCombineRoles){
		for (MenusCombineRoles menusCombineRole : menusCombineRoles) {
			delete(menusCombineRole);
		}
	}
	
	/**
	 * 根据菜单ID查询菜单角色关联信息
	 * @param menuID
	 * @return
	 */
	public MenusCombineRoles findMenusCombineRolesByMenuID(Integer menuID){
		String hql = "from MenusCombineRoles where menuID = ?";
		return findOne(hql, menuID);
	}
	
	/**
	 * 批量删除
	 * @param combineRoles
	 */
	public void deleteCombineRolesByList(List<MenusCombineRoles> combineRoles){
		deleteBatch(combineRoles);
	}
	

}
